local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_ShootAttackCtrl());

local gloves_cfg = ClientOHOH.config.Gloves

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
    self.ActionSynchronize=self.player:GetComponent(_G.CommonOHOH.load.Common_ActionSynchronize());
    self.DataBase=self.player:GetComponent(ClientOHOH.load.Client_PlayerDataComponent())
    self.ChapterCtrl=  self.player:GetComponent(ClientOHOH.load.Client_ChapterCtrl())
end;

-- 初始化攻击者信息
function M.InitAttackInfo(self)
    self.DameHpUi="UI.WeaponDamage"
    self.actionId="PlayerAttack"
    self.attcaker=self.player:GetUserId()
end

-- 监听开始射击
function M.ListenShoot(self)
    local con= self.player.ShootEvent:Connect(function()
        self:Shoot()
    end)
    table.insert(self.ConList,con)

    local con1= self.player.DeadBeforeEvent:Connect(function()
        self:dtor()
    end)
    table.insert(self.ConList,con1)
end

-- 获取伤害值
function M.GetDamge(self)
    return  self.player:GetAttackDamage()
end

-- 将伤害推送至服务器
function M.PushDamge2Server(self,lvId,mId)
    self.ActionSynchronize:Push({
        actionId= self.actionId,
        arg={
            levelId=lvId,
            monsterId=mId,
            attacker=self.attcaker
        }
    })
end

-- 子弹是否穿透
function M.IsPenetrate(self)
    return self:GetNowWeapon().isPenetrate==1
end

-- 获取子弹Id
function M.GetBulletId(self)
    return "Gloves_Bullet_"..self:GetNowWeapon().id
end

-- 寻找射击位置
function M.FindShootPos(self)
    local m,pos=self.ChapterCtrl:GetActiveChapter():findOptimalShootMonster()
    -- print(m,pos)
    return pos
end

function M.GetNowWeapon(self)
    local wid=self.DataBase:GetData("glove").equip
    local cfg=gloves_cfg[tonumber(wid)]
    assert(cfg,"武器配置表无法找到:"..wid)
    return cfg
end

function M.dtor(self)
	M.super.dtor(self);
end;

return M